package com.dao;

import com.pojo.NurseLevel;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public class NurseLevelDao extends BaseDao<NurseLevel>{

    @Override
    public NurseLevel rowMapper(ResultSet rs) {
        NurseLevel level = new NurseLevel();
        try {
            level.setId(rs.getInt("id"));
            level.setLevelName(rs.getString("level_name"));
            level.setLevelStatus(rs.getInt("level_status"));
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }


        return level;
    }

    public int addNurseLevel(NurseLevel level) {
        String sql = "INSERT INTO nurselevel(level_name,level_status) VALUES(?,?)";
        Object[] arr = {level.getLevelName(),level.getLevelStatus()};
        if (this.update(sql,arr))
            return 1;
        else return 0;
    }

    public List<NurseLevel> searchAll() {
        String sql = "SELECT id,level_name,level_status FROM nurselevel WHERE is_deleted is null OR is_deleted = 0";

        return this.findMultiple(sql,null);
    }

    public int updateNurseLevel(NurseLevel level) {
        String sql = "UPDATE nurselevel set level_name = ?,level_status = ? WHERE id = ?";
        Object[] arr = {level.getLevelName(),level.getLevelStatus(),level.getId()};
        if (this.update(sql,arr))
            return 1;
        else return 0;
    }
}
